package e.odbo.data.user.page;

import e.odbo.data.dsl.operation.Page;

public class PageManager {

    private int pageCount=0;
    private int currentPage=0;
    private int pageSize=0;

    public PageManager(int pageCount, int currentPage, int pageSize) {
        this.pageCount = pageCount;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

    public Page first(){
        currentPage=0;
        return getCurrentPage();
    }

    public Page pre(){
        if(havePre())
            currentPage--;
        return getCurrentPage();
    }

    public Page goTo(int pageNum){
        if(pageNum<=0)
            this.currentPage=0;
        else if(pageNum>=this.pageCount)
            this.currentPage=pageCount;
        this.currentPage=pageNum;
        return getCurrentPage();
    }

    public Page last(){
        this.currentPage=this.pageCount;
        return getCurrentPage();
    }

    public int getPageCount(){
        return pageCount;
    }

    public int getPageSize(){
        return pageSize;
    }

    public Page getCurrentPage(){
        return new Page(currentPage,pageSize);
    }

    public boolean havePre(){
        return currentPage>0;
    }

    public boolean haveNext(){
        return currentPage<pageCount;
    }

    public void reset(int pageCount,int pageSize,int currentPage){
        this.pageCount = pageCount;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

}
